package com.vina.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;

import javax.jdo.PersistenceManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.WebContext;

import com.vina.domain.Blog;
import com.vina.persistence.PMF;
import com.vina.utils.Utils;
import com.vina.web.thymeleaf.TemplateEngineUtil;

public class BlogEditServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
private static TemplateEngine te;
	
	public BlogEditServlet(){
		super();
		te = TemplateEngineUtil.getInstance().getEngine();
	}
	
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doService(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doService(request, response);
    }

    protected void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//    	PersistenceManager pm = PMF.get().getPersistenceManager();
//    	try{
//    		Blog b = pm.getObjectById(Blog.class, 4);
//    		pm.deletePersistent(b);
//    	}finally{
//    		pm.close();
//    	}
    	
        WebContext ctx = new WebContext(request, getServletContext(), request.getLocale());
        ctx.setVariable("urlRelativePath",Utils.getRelativeURLPath("blog/edit"));
        te.process("blog/edit", ctx, response.getWriter());

    }

}
